package com.yykj.prescription.server.controller;

import com.yykj.common.enums.ResultEnums;
import com.yykj.common.exception.NormalException;
import com.yykj.common.vo.ResultVO;
import com.yykj.prescription.client.dto.PrescriptionDetailDTO;
import com.yykj.prescription.server.dto.prescription.PatientPrescriptionSearchDTO;
import com.yykj.prescription.server.dto.prescription.PrescriptionListSearchDTO;
import com.yykj.prescription.server.service.PrescriptionService;
import com.yykj.prescription.server.vo.PrescriptionListVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/api/patient/prescription")
@Api(tags = {"患者端 -- 处方相关接口"})
public class PatientPrescriptionController {

    @ApiOperation("处方 -- 列表")
    @GetMapping("/list")
    public ResultVO<PrescriptionListVO> listPatientPrescription(PatientPrescriptionSearchDTO searchDTO){
        if(StringUtils.isEmpty(searchDTO.getUserId())){
            throw new NormalException(ResultEnums.PARAM_ERROR);
        }
        PrescriptionListSearchDTO prescriptionListSearchDTO  = new PrescriptionListSearchDTO();
        BeanUtils.copyProperties(searchDTO,prescriptionListSearchDTO);
        return ResultVO.success(prescriptionService.listPrescription(prescriptionListSearchDTO));
    }

    @GetMapping("/info/{prescriptionId}")
    @ApiOperation("处方 -- 详情")
    public ResultVO<PrescriptionDetailDTO> prescriptionDetailInfo(@PathVariable String prescriptionId){
        return ResultVO.success(prescriptionService.prescriptionInfo(prescriptionId));
    }

    private PrescriptionService prescriptionService;

    @Autowired
    public void setPrescriptionService(PrescriptionService prescriptionService) {
        this.prescriptionService = prescriptionService;
    }
}
